<?php


// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
        header('Location: index.php');
}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
?>


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>
		Administrative Page
	</title>
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
	<script type="text/javascript" language="javascript" src="jquery.js"></script> 
	<script type='text/javascript' language="javascript" src="DataTables-1.7.3/media/js/jquery.dataTables.min.js"></script>
	<style type="text/css">
	</style> 
	
	<?php
	include 'functions.php';
	?>

</head>

<body>
	<?php
			include 'headinfo.php';
		?>
	<hr />
	<div id="header">
		<?php
			$thispage = "Administrative";
			require 'menu.php';
		?>
		<!-- end #menu -->
	</div>
	<!-- end #header -->
	<!-- end #header-wrapper -->
	<div id="page">
		<div id="content">
		  	<div class="post">
		  		
			  	<h2 class="title"><a href="#">Administrative</a></h2>
							
				<p class="meta"></p>
				<?php
					$thissubpage ="Edit Crop/Category";
					require 'menu_admin.php';
				?>
				
    	<br />
    	<h2>Confirmation</h2>
		<div id="msg">
    	<p name="msg"></p>
    	
    	<?php
    	if(isset($_POST['addCrop'])){
    	if(empty($_POST['cropname'])||$_POST['cropcategory']=="select"){
    		print("You must input a crop name and select a category!");
    	}else{
    	
    	$cropname = $_POST['cropname'];
    	$categoryname= $_POST['cropcategory'];
		$firstunit = $_POST['cropfirstunit'];
		$secondunit = $_POST['cropsecondunit'];
    	$categoryid = getCategoryId($categoryname);
    	addCrop($cropname, $firstunit, $secondunit, $categoryid);
    	}
    	}
    	
    	?>
    	
    	<?php
    	if(isset($_POST['addCategory'])){
    	if(empty($_POST['categorynameAdd'])){
    		echo "Please input a category name!";
    	}else{
    	
    	
    	$categoryname = $_POST['categorynameAdd'];
    	addCategory($categoryname, NULL,NULL);
    	
    	}
    	}
    	?>
       	
       <?php
    	if(isset($_POST['deleteCrop'])){
    	if($_POST['cropname']=="select"){
    		print("You must select a crop to delete!");
    	}else{
    	
    		$cropname = $_POST['cropname'];
    		deleteCrop($cropname);
    	}
    	}
    	
    	?>
       
       <?php
    	if(isset($_POST['deleteCategory'])){
    	if($_POST['categorynameDelete']=="select"){
    		print("You must select a category to delete!");
    	}else{
    		$categoryname = $_POST['categorynameDelete'];
    		deleteCategory($categoryname);
    	}
    	}
    	
    	?>
    	
        
        
    	
    	</div>	
    	<br />
    	
    	<input type="button" value="OK" ONCLICK="window.location.href='adminPage.php'"></input>
     
          				
			</div>
		</div>
	</div>
	
<div style="clear: both;">&nbsp;</div>
	
<div id="footer">
	<p>Copyright (c) 2010 Dilmun Hill Team.</p>
</div>
<!-- end #footer -->
	
</body>

</html>